package com.wandian.texas;

import java.nio.ByteBuffer;
import com.wandian.texas.entity.UserInfoEntity;

/**
 * 给command线程池扔的一个带session对象的命令
 * 
 * @author long
 * 
 */
public class CommandObject extends BaseCommandObject {

	


	public CommandObject() {
		super();
		// bytes = ByteBuffer.allocate(1024);
		// bytes.order(ByteOrder.LITTLE_ENDIAN);
	}

	public CommandObject(long delay) {
		super(delay);
	}

	public CommandObject(long _initialDelay, long _period, int _totalCount) {
		super(_initialDelay, _period, _totalCount);
	}

	public CommandObject(SessionObject _sessionObject, DataPacket _dataPacket) {
		this();
		this.sessionObject = _sessionObject;
		this.dataPacket = _dataPacket;
		this.dbIndex = -1;
		if (dataPacket != null) {
			this.setCmd(this.dataPacket.cmdId);
		}
	}

	public CommandObject(DataPacket _dataPacket, UserInfoEntity user) {
		this();
		this.dataPacket = _dataPacket;
		this.sessionObject = new SessionObject(null);
		this.setUser(user);
		if (dataPacket != null) {
			this.setCmd(this.dataPacket.cmdId);
		}
	}

	


	/* public int getDataLen() { return this.bytes.remaining(); }
	 * 
	 * public ByteBuffer getBytes() { return bytes; }
	 * 
	 * public void writeBegin() { bytes.clear(); }
	 * 
	 * public void writeByte(byte value) { bytes.put(value); }
	 * 
	 * public void writeShort(Short value) { bytes.putShort(value); }
	 * 
	 * public void writeInt(int value) { bytes.putInt(value); }
	 * 
	 * public void writeString(String msg) { ByteBuffer temp =
	 * ProtoBufUtil.getInstance().encode(msg, true);
	 * bytes.putInt(temp.remaining() + 1);// 写入长度 bytes.put(temp);
	 * bytes.put((byte) 0);// 结尾标识符 }
	 * 
	 * public void writeEnd() { bytes.flip(); }
	 * 
	 * public String readString() { // length|bytes String msgString = ""; int
	 * length = bytes.getInt(); if (bytes.remaining() >= length) { int oldlimit
	 * = bytes.limit(); int oldPosition = bytes.position();
	 * bytes.limit(bytes.position() + length - 1); if (length > 0) { msgString =
	 * ProtoBufUtil.getInstance().decode(bytes, true); } bytes.limit(oldlimit);
	 * bytes.position(oldPosition + length); } return msgString; }
	 * 
	 * public void setBytes(byte[] _bytes) { this.bytes.clear(); if (_bytes !=
	 * null && _bytes.length > 0) this.bytes.put(_bytes); this.bytes.flip(); } */
	/* public SessionObject getSessionObject() { return sessionObject; }
	 * 
	 * public void setSessionObject(SessionObject sessionObject) {
	 * this.sessionObject = sessionObject; } */
}
